/**
 * Created by win7 on 2017/3/13.
 */
import React from "react";
import Relay from "react-relay";
import Confirm from "../../common/Confirm";
import "./css/People.css";
import Addstaff from "./Addstaff";
import FindUserListMutation from "./mutation/FindUserListMutation";
import PeopleDetail from "./PeopleDetail";
import ReactKey from "../../util/ReactKey";
import Util from "../../util/Util";


/*人员管理*/

export default class People extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            Department: [],
            leftTabstate: false,
            defaultValue: '',
            status: 1,
        }
        this.Style = {}
        this.Department = [];
        this.partid = ''
        this.deparmentc = {}
        this.peopleData = [];
        this.defaultValue = '';
        this.rid = '';
        this.status = 1;
        this.choseuidlist = []
        this.index = 0;
        this.totalresult = '';
    }

    serchpeople(size, num) {
        Relay.Store.commitUpdate(
            new FindUserListMutation({
                pageSize: size,
                pageNum: num,

            }),
            {
                onFailure: () => {

                },
                onSuccess: (response) => {
                    let errorcode = response.findUserList.findUserList.errorCode
                    if (errorcode == 0) {
                        let userModelList = response.findUserList.findUserList.userModelList;
                        let totalresult = response.findUserList.findUserList.totalResult;
                        this.totalresult = totalresult;
                        if (userModelList != null && userModelList.length != 0) {
                            this.refs.peopledetail.setState({
                                peopleData: userModelList,
                                totalresult: totalresult,
                            });
                        } else {
                            this.refs.peopledetail.setState({
                                peopleData: [],
                                totalresult: 0,
                            });
                            this.refs.peopledetail.refs.pagination.setState({
                                text: ''
                            });
                        }
                    }
                }
            }
        )
    }


    componentWillMount() {
        this.Style.add_people = {
            width: "60px",
            height: "44px",
            paddingLeft: "18px",
            lineHeight: "44px",
            display: "block",
            backgroundColor: "#a0d468",
            marginBottom: 49,
            color: "#fff",
            marginTop: 5
        }

        this.Style.peodiv = {
            marginLeft: "900px"

        }
        this.serchpeople(10, 1);
    }


    changetab(index) {

    }

    editstaffinfo(phone, name, uid, roleId) {
        this.refs.addstaff.setState({
            visible: true,
            conname: '确定',
            title: '编辑用户信息',
            password: "*******"
        }, () => {
            this.refs.addstaff.refs._telephone.setState({
                text: phone,
                disabled: true
            });

            this.refs.addstaff.refs._enterpriseName.setState({
                text: name
            });

            this.refs.addstaff.setState({
                uid: uid
            })
            this.refs.addstaff.initHit();
        });

    }

    //批量修改工作弹窗出现
    modifyjob() {
        this.refs.modifyjob.setState({
            visible: true
        })
    }

    //批量停用员工弹窗的实现
    muchforbid() {
        this.refs.muchforbid.setState({
            visible: true
        })
    }

    //添加员工弹窗出现
    addpeople() {
        this.refs.addstaff.setState({
            visible: true,
            conname: '添加人员',
            title: '新建用户',
            uid: "",
            password: "123456"
        })
        this.refs.addstaff.initHit();
    }

    functest() {
        this.refs.deletepart.setState({
            visible: true
        })
    }

    sureClick() {
        let pageNum = this.refs.peopledetail.refs.pagination.state.text;
        this.serchpeople(10, pageNum);
    }

    getchosepeople(uidlist) {
        this.choseuidlist = uidlist
    }

    render() {
        return (
            <div >
                <div style={this.Style.sectioncontext}>
                    <div className="user_div">
                        <div className="new_user_father_en" style={!Util.authorityCheck("people") ? {display: 'none'} :{}}>
                            <Confirm tcontext={'新建用户'} className="company_btn-tit" style={{backgroundColor:"#a0d468",color:"#fff",width:"120px",height:"35px"}}  touch={this.addpeople.bind(this)}/>
                        </div>
                        {/*<ul className="lot_position">*/}
                        {/*<li><Confirm tcontext={'批量停用员工'} style={this.Style.public_lot2}*/}
                        {/*touch={this.muchforbid.bind(this)}/></li>*/}
                        {/*</ul>*/}
                    </div>
                    <PeopleDetail peopleDetailData={this.peopleData} ref={'peopledetail'}
                                  getchosepeople={this.getchosepeople.bind(this)}
                                  editstaffinfo={this.editstaffinfo.bind(this)}
                                  serchpeople={this.serchpeople.bind(this)}
                    />
                </div>


                {/*弹窗*/}
                <Addstaff ref={'addstaff'} defaultValue={this.state.defaultValue}
                          callbackParentSure={this.serchpeople.bind(this)}
                          callbackParentList={this.sureClick.bind(this)}/>

            </div>
        )
    }
}